package com.xbongbong.saas.factory.business;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.ErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.TemplateErrorCodeEnum;
import com.xbongbong.saas.enums.BusinessTypeToServiceEnum;
import com.xbongbong.saas.service.FormatSpecialBusinessService;
import com.xbongbong.saas.service.impl.AssembleServiceImpl;
import com.xbongbong.saas.service.impl.InstockServiceImpl;
import com.xbongbong.saas.service.impl.InventoryServiceImpl;
import com.xbongbong.saas.service.impl.OutstockServiceImpl;
import com.xbongbong.saas.service.impl.ProductServiceImpl;
import com.xbongbong.saas.service.impl.RefundServiceImpl;
import com.xbongbong.saas.service.impl.ReturnedPurchaseServiceImpl;
import com.xbongbong.saas.service.impl.TransferServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author
 */
@Component
public class AutoRegisterHandleSpecialBusinessFactory {

    private static final Logger LOG = LoggerFactory.getLogger(AutoRegisterHandleSpecialBusinessFactory.class);
    /**
     * 存储特殊业务策略
     */

    @Resource
    private InstockServiceImpl instockService;
    @Resource
    private OutstockServiceImpl outstockService;
    @Resource
    private AssembleServiceImpl assembleService;
    @Resource
    private ProductServiceImpl productService;
    @Resource
    private RefundServiceImpl refundService;
    @Resource
    private ReturnedPurchaseServiceImpl returnedPurchaseService;
    @Resource
    private InventoryServiceImpl inventoryService;
    @Resource
    private TransferServiceImpl transferService;



    /**
    * 通过map获取策略，当增加新的策略时无需修改代码，对修改封闭，对扩展开放，遵循开闭原则
     */
    public  FormatSpecialBusinessService getSpecialBusiness(BusinessTypeToServiceEnum businessTypeToServiceEnum) throws XbbException {
        switch (businessTypeToServiceEnum) {
            case REFUND:
                return refundService;
            case INSTOCK:
                return instockService;
            case OUTSTOCK:
                return outstockService;
            case ASSEMBLE:
                return assembleService;
            case PRODUCT:
                return productService;
            case TRANSFER:
                return transferService;
            case INVENTORY:
                return inventoryService;
            case RETURNED_PURCHASE:
                return returnedPurchaseService;
                default:
                    throw new XbbException(TemplateErrorCodeEnum.API_ERROR_350006);
        }
    }

}
